<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <button>点击</button>
    <script>
// 查询参 ：querystring
/* 
https://huodong.taobao.com/wow/a/act/tao/dailyact/5146/wupr?spm=a21bo.jianhua.201867-main.15.5af911d9JJS3KS&wh_pid=dailyAct-265555&v=2483e735cab1dcee499ab6218cd24e1c&wh_random_str=1



*/
        let obj = {
            myname:"zhangsan",
            age:20,
            height:"178cm"
        }

        // function o2s(obj){
        //     let keys = Object.keys(obj);
        //     let values = Object.values(obj);
        //     var arr =   keys.map((key,index)=>{
        //         return `${key}=${values[index]}`;
        //     })
        //     // console.log(arr);
        //     return arr.join("&");
        // }

    const o2s = obj=>Object.keys(obj).map((key,index)=>`${key}=${Object.values(obj)[index]}`).join("&");




        document.querySelector("button").onclick = function(){
            // 跳转的同时 携带obj参数
            window.location.href = `b.html?${o2s(obj)}`;
        }

        // 把对象转成 固定格式的字符串 
        // ?myname=zhangsan&age=20

       
    //   var res =   o2s(obj);
    //   console.log(res);




    </script>
</body>
</html>